package main

import (
"fmt"

"github.com/garyburd/redigo/redis"
)
var network string = "tcp"
var address string = "127.0.0.1:6379"
func main() {
	conn, err := redis.Dial(network, address)
	defer conn.Close()
	defer conn.Do("flushDB")
	if err != nil {
		fmt.Println(err)
	}
	conn.Do("set", "name", "hwang")
	reply,getErr := conn.Do("get","name")
	//fmt.Println(string(reply.([]byte))) //变量必须是interface{}才能类型断言
	reply1,_ := redis.String(reply,getErr)
	fmt.Println(reply1)

	conn.Do("hset","stu","name","ryan")
	replyHash,_ := redis.String(conn.Do("hget","stu","name"))
	fmt.Println(replyHash)

	conn.Do("hmset","stu1","name","aaa","age","33","salary","33333.3","address","浦江路1143号")
	replysHash,_ := redis.StringMap(conn.Do("hgetall","stu1"))
	fmt.Println(replysHash)



	conn.Do("lpush","nameList","lulu","ruirui","yinyin")
	replyList,_ := redis.Strings(conn.Do("lrange","nameList",0,-1))
	fmt.Println(replyList)

	var pool *redis.Pool = &redis.Pool{
		MaxIdle:8, //最大空闲连接数
		MaxActive:0, //和数据库最大的连接数 0 是不限制
		IdleTimeout:100, //最大空闲时间
		Dial: func() (redis.Conn, error) {
			return redis.Dial(network, address)
		},
	}
	defer pool.Close()
	poolConn := pool.Get()
	defer poolConn.Close()
	poolConn.Do("set","question","are you a pig?")
	q,_ := redis.String(poolConn.Do("get","question"))
	fmt.Println(q)
}

func initPool(){

}